def print_diamond(n):
    for i in range(n):
        print(' ' * (n - i - 1) + '*' * (2 * i + 1))
    for i in range(n - 2, -1, -1):
        print(' ' * (n - i - 1) + '*' * (2 * i + 1))

print_diamond(5)  # 打印一个5层的菱形
def print_narcissistic_numbers():
    for num in range(100, 1000):
        digits = [int(digit) for digit in str(num)]
        if sum([d**3 for d in digits]) == num:
            print(num)

print_narcissistic_numbers()
def print_multiplication_table():
    for i in range(1, 10):
        for j in range(1, i + 1):
            print(f"{j}*{i}={j*i}", end="  ")
        print()

print_multiplication_table()
def print_perfect_numbers(limit):
    for num in range(2, limit + 1):
        factors_sum = sum([i for i in range(1, num) if num % i == 0])
        if factors_sum == num:
            print(num)

print_perfect_numbers(1000)  # 打印1000以内的完数
def print_primes(limit):
    for num in range(2, limit + 1):
        is_prime = True
        for i in range(2, int(num**0.5) + 1):
            if num % i == 0:
                is_prime = False
                break
        if is_prime:
            print(num)

print_primes(100)  # 打印100以内的质数
def print_fibonacci_sequence(n):
    fib_seq = [0, 1]
    while len(fib_seq) < n:
        fib_seq.append(fib_seq[-1] + fib_seq[-2])
    print(fib_seq)

print_fibonacci_sequence(10)  # 打印前10个斐波那契数

##打印水仙花数
def diagrmond(n):
    for i in range(n):
        print(" " * (n-i-1)+"*"*(2*i+1))
    for i in range(n-2,-1,-1):
        print(" " * (n-i-1)+"*"*(2*i+1))
diagrmond(5)

def feibonaqi(n):
    init=[0,1]
    while len(init)<n:
        init.append(init[-1]+init[-2])
    print(init)
feibonaqi(50)

def print_primes2(n):
    for i in range(2 , n+1):
        is_prime = True
        for j in range(2,int(i**0.5)+1):
            if i%j==0:
                is_prime=False
                break
        if is_prime:
            print(i)
print_primes2(100)

def feibonaqi2(n):
    fei_seq=[0,1]
    for i in range(n):
        fei_seq.append(fei_seq[-1]+fei_seq[-2])
    print(fei_seq)
feibonaqi2(10)